<template>
  <div>
    <el-button type="primary" class="refresh" @click="onCheckedOut"
      >导出</el-button
    >
  </div>
</template>

<script>
export default {
    props:{
       url:String
    },
    data(){
      return{
          Url:this.url,
          name:""
      }
    },
    mounted(){
      this.name = this.Url.substring(49)
      // console.log('====================',this.name)
    },
  methods: {
    onCheckedOut(){    
      // 导出
      this.ajax
        .get(this.Url, {
          responseType: "blob",
        })
        .then((res) => {
          console.log(res);
          if (!res) return;
          let blob = new Blob([res.data],{
            type: "application/vnd.ms-excel;charset=utf-8",
          });
          let url = window.URL.createObjectURL(blob);
          let aLink = document.createElement("a");
          aLink.style.display = "none";
          aLink.href = url;
          aLink.setAttribute("download", `${this.name}.xlsx`); // 下载的文件
          document.body.appendChild(aLink);
          aLink.click();
          document.body.removeChild(aLink);
          window.URL.revokeObjectURL(url);
        })
          .catch(error => {
          this.$message.error(error);
        });
    },
  },
};
</script>

<style  scoped>
</style>



        
        

        

      

       

        
       

       

       
      